package com.tablepet.activities.main;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.tablepet.R;
import com.tablepet.activities.App;
import com.tablepet.activities.preview.PipActivity;
import com.tablepet.databinding.ActivityMainBinding;
import com.tablepet.utils.Utils;

public class MainActivity extends AppCompatActivity {
    private ActivityMainBinding binding;
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//实现状态栏图标和文字颜色为暗色

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getSupportActionBar().hide();
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.navigation_showcase, R.id.navigation_shop, R.id.navigation_bid,R.id.navigation_me).build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(binding.navView, navController);

        @SuppressLint("CommitPrefEdits") SharedPreferences.Editor edit = App.sp.edit();
        edit.putFloat("PreviePet",-1);
        edit.putBoolean("isChoosed",true);
        DisplayMetrics outMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getRealMetrics(outMetrics);
        edit.putInt("screenWidth",outMetrics.widthPixels);
        edit.putInt("screenHeight",outMetrics.heightPixels);
        edit.apply();
        startActivity(new Intent(MainActivity.this, PipActivity.class));
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            SharedPreferences.Editor edit1 = App.sp.edit();
            edit1.putBoolean("isChoosed", true);
            edit1.apply();
            App.configChange = true;
            Utils.backToDesktop(this);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}